//
// Created by bjliuyong on 2021/7/17.
//

#ifndef JVM_ARRAY_H
#define JVM_ARRAY_H

#include "utilities/globalDefinitions.h"

// Array for metadata allocation

template<typename T>
class Array {
protected:
    int _length;                                 // the number of array elements
    T _data[1];                                // the array memory

    void initialize(int length) {
        _length = length;
    }

public:

    // Turn off copy constructor and assignment operator.
    Array(const Array<T>&);

    void* operator new(size_t size,int length){
        size_t s = sizeof(int) + sizeof(T) * length;
        return malloc(s);
    }

    // standard operations
    int  length() const                 { return _length; }
    T* data()                           { return _data; }
    bool is_empty() const               { return length() == 0; }

    T at(int i) const { return _data[i]; }

    void at_put(const int i, const T &x) { _data[i] = x; }

    explicit Array(int length) : _length(length) {}
};



#endif //JVM_ARRAY_H
